﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using VISAInstrument.Ports;

namespace 万用表34460A
{
    public class 采集
    {
        private static PortOperatorBase _portOperatorBase;
        [VM.Shared.TestAttribute.ExposedMethodAttribute("")]
        public bool 电流A(string 端口名称, out double 电流值, out string 错误信息)
        {
            错误信息 = "";
            电流值 = 0.0;
            try
            {
                _portOperatorBase = new UsbPortOperator(端口名称);
                _portOperatorBase.Open();
                _portOperatorBase.Write(":MEASure:CURRent:DC?");
                Thread.Sleep(100);
                string result = _portOperatorBase.ReadLine();
                double.TryParse(result, out 电流值);

                电流值 = Math.Abs(电流值);
                _portOperatorBase.Close();
            }
            catch (Exception ex)
            {
                错误信息 = ex.Message;
            }

            return true;
        }
        [VM.Shared.TestAttribute.ExposedMethodAttribute("")]
        public bool 电流mA(string 端口名称, out double 电流值, out string 错误信息)
        {
            错误信息 = "";
            电流值 = 0.0;
            try
            {
                _portOperatorBase = new UsbPortOperator(端口名称);
                _portOperatorBase.Open();
                _portOperatorBase.Write(":MEASure:CURRent:DC?");
                Thread.Sleep(100);
                string result = _portOperatorBase.ReadLine();
                double.TryParse(result, out 电流值);

                电流值 = Math.Abs(电流值 * 1000);
                _portOperatorBase.Close();
            }
            catch (Exception ex)
            {
                错误信息 = ex.Message;
            }

            return true;
        }

        [VM.Shared.TestAttribute.ExposedMethodAttribute("")]
        public bool 电压(string 端口名称, out double 电压值, out string 错误信息)
        {
            错误信息 = "";
            电压值 = 0.0;
            try
            {
                _portOperatorBase = new UsbPortOperator(端口名称);
                _portOperatorBase.Open();
                _portOperatorBase.Write(":MEASure:VOLTage:DC?");
                Thread.Sleep(100);
                string result = _portOperatorBase.ReadLine();
                double.TryParse(result, out 电压值);
                电压值 = Math.Abs(电压值);
                _portOperatorBase.Close();
            }
            catch (Exception ex)
            {
                错误信息 = ex.Message;
            }

            return true;
        }
    }
}
